layui.define('my_send', function(exports){
  var $ = layui.$
  ,http_proxy = layui.http_proxy;
 // 实时报警
 function realTime(){
    $.ajax({
        type : "get",
        async : false, //异步执行
        url : http_proxy("/alarm/realTimeAlerts"),
        dataType : "json", //返回数据形式为json
        success : function(data) {
          var str = '';
          var data = data.data;
          data.sort(function(a,b){
            return a.alarmTime < b.alarmTime ? 1 : -1;
          })
          for (var i = 0; i < data.length; i++) {
              if(data[i].alarmRank === 1){
                  str += '<li class="alarmRank1">'+'<span class="name">'+ data[i].stationCn+'</span>'+'<span class="name">'+ data[i].alarmSystem + data[i].alarmMessage +'</span>'+'' +
                      '<span class="site">'+data[i].alarmLevel+'</span>'+'<span class="gsmc">'+ data[i].alarmTime+'</span>'+'</li>';
              }else if(data[i].alarmRank === 2){
                  str += '<li class="alarmRank2">'+'<span class="name">'+ data[i].stationCn+'</span>'+'<span class="name">'+ data[i].alarmSystem + data[i].alarmMessage +'</span>'+'' +
                      '<span class="site">'+data[i].alarmLevel+'</span>'+'<span class="gsmc">'+ data[i].alarmTime+'</span>'+'</li>';
              }
              else if(data[i].alarmRank === 3){
                str += '<li class="alarmRank3">'+'<span class="name">'+ data[i].stationCn+'</span>'+'<span class="name">'+ data[i].alarmSystem + data[i].alarmMessage +'</span>'+'' +
                    '<span class="site">'+data[i].alarmLevel+'</span>'+'<span class="gsmc">'+ data[i].alarmTime+'</span>'+'</li>';
            }
            else if(data[i].alarmRank === 4){
              str += '<li class="alarmRank4">'+'<span class="name">'+ data[i].stationCn+'</span>'+'<span class="name">'+ data[i].alarmSystem + data[i].alarmMessage +'</span>'+'' +
                '<span class="site">'+data[i].alarmLevel+'</span>'+'<span class="gsmc">'+ data[i].alarmTime+'</span>'+'</li>';
            }
          }
          $('.networkRealTime ul').html(str);
        },
        error : function(errorMsg) {
            alert("请求数据失败");
        }
    });
  }
  // $(function(){
  //   realTime();
  //   setInterval(function() {
  //     realTime();
  //   }, 10000);
  // })
    realTime();
    $.ajax({
        type : "get",
        async : false, //异步执行
        url :http_proxy('/alarm/indexGetAlarmSum'),
        dataType : "json", //返回数据形式为json
        success : function(data) {
            let strLine="";
            allNetTable = data.data;
            for (var j = 0; j <  allNetTable.length; j++) {
                $('#'+'line'+allNetTable[j].Line+'_alarm').html(allNetTable[j].number[0]);
                $('#'+'line'+allNetTable[j].Line+'_device').html(allNetTable[j].number[1]);
            }
        },
        error : function(errorMsg) {
            alert("请求数据失败");
        }
    });
    // 车站故障统计TOP10
     $.ajax({
      type : "get",
      async : false, //异步执行
      url : http_proxy("/alarm/indexGetAlarmTop"),
      dataType : "json", //返回数据形式为json
      success : function(data) {
        stationAlarmTop = data.data;
      },
      error : function(errorMsg) {
          alert("请求数据失败");
      }
    });

    // 各专业故障统计
    var myChart = echarts.init(document.getElementById("proFaultStatistics"));
    option = {
        title:{
            text:'22718',
            x: 'center',
            y: 'center',
            textStyle: {
                fontWeight: 'normal',
                color: '#f8f80d',
                fontSize: '25'
            },
        },
        tooltip: {
            show: true,
            trigger: 'item',
            formatter: "{b}: {c} ({d}%)"
        },
        series: [
            {
                type:'pie',
                selectedMode: 'single',
                radius: ['55%', '70%'],
                color: ["#8faadc", "#ffe699", "#ffc000"],
                label: {
                    normal:{
                        formatter: "{b}\n",
                        padding: [0, -40],
                        textStyle: {
                            color: '#606266',
                            fontWeight: "bold",
                            fontSize: 12
                        }
                    }
                },
                labelLine: {
                    normal: {
                        length: 20,
                        length2: 50,
                    }
                },
                data:[
                    {value:900, name:'PSCADA'},
                    {value:879, name:'FAS'},
                    {value:1600, name:'EMCS'},
                ],
                // data:dataValueList,
                itemStyle: {
                    normal: {
                        label: {
                            show: true,
                            // formatter: "{b} : {c} ({d}%)"
                        },
                        borderWidth:5, //设置border的宽度有多大
                        borderColor:'#fff',
                        labelLine: { show: true }
                    }
                }
            },
        ]
    };
    myChart.setOption(option);
  // 故障趋势
  var myChart = echarts.init(document.getElementById("faultFrend"));
  option = {
    tooltip: {
      trigger: 'axis'
  },
  color:['#6a8ed0','#ed6f00'],
  grid: {
      left: '3%',
      right: '5%',
      bottom: '0%',
      top:'10%',
      containLabel: true
  },
  xAxis: {
      type: 'category',
      // boundaryGap:false,
      axisLabel:{
        interval:0,
        rotate:45,
        margin:2,
        textStyle:{
          color:"#606266"
        }
      },
      axisLine: {
        lineStyle: {
            color:'#606266',
            width:'1'
        }
      },
      axisTick: {
          show: false
      },
      data: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']
  },
  yAxis: {
      type: 'value',
      axisLabel:{
        interval:0,
        textStyle:{
          color:"#606266"
        }
      },
      axisLine: {
        lineStyle: {
            color:'#606266',
            width:'1'
        }
      },
      splitLine :{    //网格线
          lineStyle:{
              type:'dotted'    //设置网格线类型 dotted：虚线   solid:实线
          },
          show:true //隐藏或显示
      },
      axisTick: {
          show: false
      }
  },
  series: [
      {
          name:'出口流量',
          smooth:true,
          symbolSize: 8, //折线点的大小
          itemStyle: {
              normal: {
                  borderWidth: 3,
              }
          },
          type:'line',
          stack: '总量1',
          data:[30, 405, 600, 250, 390,500,620,750,590,40,450,200]
      },
      {
          name:'入口流量',
          smooth:true,
          symbolSize: 8, //折线点的大小
          itemStyle: {
              normal: {
                  borderWidth: 3,
              }
          },
          type:'line',
          stack: '总量2',
          data:[190, 170, 200, 390, 420,580,780,610,605,420,560,380]
      },
  ]
};
myChart.setOption(option);
// 车站故障统计TOP10
  var stationAlarm = echarts.init(document.getElementById('stationFaultStatistics'));
  var option;
  option = {
    color: ['#3398DB'],
    tooltip: {
      trigger: 'axis',
      axisPointer: { // 坐标轴指示器，坐标轴触发有效
        type: 'shadow' // 默认为直线，可选为：'line' | 'shadow'
      }
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '0%',
        top:'15%',
      containLabel: true
    },
    xAxis: [{
      type: 'category',
      axisLine: {
        lineStyle: {
            color:'#3398DB',
            width:'1'
        }
      },
      axisLabel: {
        rotate:45,
        interval:0,
        textStyle: {
            color: '车站故障'
        }
      },
      data:stationAlarmTop.xData,
      axisTick: {
        alignWithLabel: true,
        lineStyle:{
          color : '#3398DB',	
        }
      },
    }],
    yAxis: [{
      // name: "（数量）",
      type: 'value',
      nameTextStyle: {
          color: "#606266",
          fontSize: 16
      },
      type: 'value',
      axisLine: {
        lineStyle: {
            color:'#3398DB',
            width:'1'
        }
      },
      axisLabel: {
        textStyle: {
            color: '#606266'
        }
      },
      splitLine :{    //网格线
        lineStyle:{
            type:'dotted'    //设置网格线类型 dotted：虚线   solid:实线
        },
        show:true //隐藏或显示
      }

    }],
    series: [{
      name: '站点',
      type: 'bar',
      data:stationAlarmTop.yData
    }]
  };
  stationAlarm.setOption(option);

  //   $(function() {
  //     var $this = $(".networkRealTime");
  //     var scrollTimer;
  //     $this.hover(function() {
  //         clearInterval(scrollTimer);
  //     }, function() {
  //         scrollTimer = setInterval(function() {
  //             scrollContent($this);
  //         }, 0);
  //     }).trigger("mouseout");
  // });

  //   function scrollContent(obj) {
  //       var $self = obj.find("ul:first");
  //       var lineHeight = $self.find("li:first").height() + 10; //获取行高
  //       $self.animate({
  //           "margin-top": -lineHeight + "px"
  //       }, 1000, function() {
  //           $self.css({
  //               "margin-top": "0px"
  //           }).find("li:first").appendTo($self); //appendTo能直接移动元素而不是复制，被appendto的元素位置发生变化
  //       })
  //   }
  exports('homePage', {})
});



  
  